package peng.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import peng.bean.AuserBridging;
import peng.bean.PageBeanAdmin;
import peng.bean.PageResult;
import peng.controller.AppResult.ResultMessage;
import peng.dao.AdminUserGroupMapper;
import peng.dao.AdminUserMapper;
import peng.entity.AdminUser;

import peng.entity.AdminUserGroup;
import peng.service.AdminUserGroupService;
import peng.service.AdminUserService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class AdminUserServiceImpl implements AdminUserService {

    @Autowired
    AdminUserMapper adminUserMapper;
    @Autowired
    AdminUserGroupService adminUserGroupService;

    @Override
    public int insert(AdminUser record) {
        return adminUserMapper.insert(record);
    }

    @Override
    public int insertSelective(AdminUser record) {
        return adminUserMapper.insertSelective(record);
    }

    @Override
    public AdminUser selectByPrimaryKey(Integer id) {
        return adminUserMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(AdminUser record) {
        return adminUserMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(AdminUser record) {
        return adminUserMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<AdminUser> selectAll() {
        return adminUserMapper.selectAll();
    }

    @Override
    public int selectAccount(String accountOrphone) {
        return adminUserMapper.selectAccount(accountOrphone);
    }



    @Override
    public AdminUser selectByAdminAndPass(String accountOrphone) {
        return adminUserMapper.selectByAdminAndPass(accountOrphone);
    }


    @Override
    public PageResult queryselect(PageBeanAdmin pageBeanAdmin) {
        /**
         * count 返回查询的结果
         * //差总数   一个查list<result>
         */
        int count = adminUserMapper.selectCountForPage(pageBeanAdmin);
        //System.out.println("------------------"+count);
        //如果查询结果大于0，说明有查询到数据
        if (count > 0){
            List<Map<String,Object>> list = adminUserMapper.selectListByPage(pageBeanAdmin);
//                    List<AuserBridging> addlist = new ArrayList<>();
//
//                for (AdminUser user:list){
//                    AuserBridging bridging = new AuserBridging();
//                    bridging.setId(user.getId());
//                    bridging.setName(user.getName());
//                    bridging.setAccount(user.getAccount());
//                    if (user.getSex().equals("1")){
//                        bridging.setSex("男");
//                    }else if (user.getSex().equals("0")){
//                        bridging.setSex("女");
//                    }
//                   String group = adminUserGroupService.selectByPrimaryKey(user.getRoleId()).getName();
//
//                    bridging.setGroupName(group);
//                    bridging.setTelphone(user.getTelphone());
//                    if (user.getStatus().equals(ResultMessage.code_status_OK)){
//                        bridging.setStatus("可用");
//                    }else {
//                        bridging.setStatus("不可用");
//                    }
//                    bridging.setDescription(user.getDescription());
//                    bridging.setCreateTime(user.getCreateTime());
//                    bridging.setUpdateTime(user.getUpdateTime());
//                    list.add(bridging);
//                }

            return new PageResult(list,count,pageBeanAdmin.getCurrentPage(),pageBeanAdmin.getPageSize());
        }

        return new PageResult(new ArrayList<>(),0,1,pageBeanAdmin.getPageSize());
    }

    @Override
    public List<Map<String,Object>> selectListByPage(PageBeanAdmin vo) {
        return adminUserMapper.selectListByPage(vo);
    }

    @Override
    public int selectByid(Integer id) {
        return adminUserMapper.selectByid(id);
    }

}
